home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TAddrInet.cp < prev    next >
Encoding:
Text File  |  1996-01-11  |  3.5 KB  |  110 lines  |  [TEXT/CWIE]

  1. //    TAddrInet.cp - Macintosh OpenTransport network "address family independent" class object
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TAddrInet.h"
  18.  
  19.  
  20. // ---------------------------------------------------------------------------
  21. //     Clone()
  22. // ---------------------------------------------------------------------------
  23. //    Clone
  24. TAddr*    TAddrInet::Clone()
  25. {
  26.     return new TAddrInet(fAddress.fHost, fAddress.fPort);
  27. };
  28.  
  29. // ---------------------------------------------------------------------------
  30. //     operator==
  31. // ---------------------------------------------------------------------------
  32. //    Equality check
  33.  
  34. Boolean operator== (const TAddrInet& a1, const TAddrInet& a2)
  35. {
  36.     return (    ((a1.fAddress.fAddressType == AF_INET) && (a2.fAddress.fAddressType == AF_INET)) 
  37.                  &&(a1.fAddress.fPort == a2.fAddress.fPort) 
  38.                 && ( (a1.fAddress.fHost == a2.fAddress.fHost) 
  39.                     || (a1.fAddress.fHost == kOTAnyInetAddress) 
  40.                     || (a2.fAddress.fHost == kOTAnyInetAddress))) ;
  41. };
  42.  
  43. // ---------------------------------------------------------------------------
  44. //     operator!=
  45. // ---------------------------------------------------------------------------
  46. //    Non Equality check
  47. Boolean operator!= (const TAddrInet& a1, const TAddrInet& a2)
  48. {
  49.     return !(    ((a1.fAddress.fAddressType == AF_INET) && (a2.fAddress.fAddressType == AF_INET)) 
  50.                  &&(a1.fAddress.fPort == a2.fAddress.fPort) 
  51.                 && ( (a1.fAddress.fHost == a2.fAddress.fHost) 
  52.                     || (a1.fAddress.fHost == kOTAnyInetAddress) 
  53.                     || (a2.fAddress.fHost == kOTAnyInetAddress))) ;
  54. };
  55.  
  56. // ---------------------------------------------------------------------------
  57. //     operator= 
  58. // ---------------------------------------------------------------------------
  59. //    Asignment
  60.  
  61. TAddrInet& TAddrInet::operator= ( const TAddrInet& a)
  62. {
  63.     fAddress.fAddressType     = a.fAddress.fAddressType;
  64.     fAddress.fPort             = a.fAddress.fPort;
  65.     fAddress.fHost             = a.fAddress.fHost;
  66.     return *this;
  67. }
  68.  
  69.  
  70. //TAddrInet& TAddrInet::operator= ( const TNetbuf* n)
  71. //{
  72. //    InetAddress* data = (InetAddress*) n->buf;
  73. //    fAddress = *data;
  74. //    return *this;
  75. //};
  76.  
  77.  
  78. // ---------------------------------------------------------------------------
  79. //     operator<<
  80. // ---------------------------------------------------------------------------
  81. //    Stream out
  82. ostream &operator<< (ostream& s, const TAddrInet& a)
  83. {
  84.     char     buf[32];
  85.  
  86.     ::OTInetHostToString( a.fAddress.fHost, buf); 
  87.     s << buf << " :" << a.fAddress.fPort;
  88.     return s;
  89. };
  90.  
  91.  
  92. // ---------------------------------------------------------------------------
  93. //     operator>>
  94. // ---------------------------------------------------------------------------
  95. //    Stream input
  96.  
  97.  
  98.  
  99. istream &operator>> (istream& s, TAddrInet& a)
  100. {
  101.     char     buf[32];
  102.     s >> buf;
  103.     
  104.     a.fAddress.fAddressType = AF_INET;
  105.     a.fAddress.fPort  =  0; // **** FIX THIS **** this to support Port Stream in..
  106.     ::OTInetStringToHost( buf, &a.fAddress.fHost); 
  107.     
  108.     return s   ;
  109. };
  110.